package com.mo.controller;

import org.redisson.api.RRateLimiter;
import org.redisson.api.RateIntervalUnit;
import org.redisson.api.RateType;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 墨渐生微
 * @program mo-all
 * @apiNote
 * @since 2022/11/23
 */
//@RestController
@RequestMapping("/rate-limiter")
public class RateLimiterController {

    @Autowired
    private RedissonClient redissonClient;

    @GetMapping
    public String test() {
        RRateLimiter rateLimiter = redissonClient.getRateLimiter("");
        // 60s 20个令牌
        rateLimiter.trySetRate(RateType.OVERALL, 20, 60, RateIntervalUnit.SECONDS);
        return "";
    }
}
